<?php

class FileNotFoundException extends Exception {
}

class XML extends SimpleXMLElement {
	public static function create($tag) {
		return new XML('<' . $tag . '/>');
	}

	public function save($file) {
		$domNode = dom_import_simplexml($this);
		$dom = new DOMDocument('1.0');
		$domNode = $dom->importNode($domNode, true);
		$dom->appendChild($domNode);
		$dom->formatOutput = TRUE;

		$dom->save($file);
	}

	public static function load($fileName) {
		if (file_exists($fileName)) {
			return simplexml_load_file($fileName, 'XML');
		} else {
			throw new FileNotFoundException('The XML file "' . $fileName . '" does not exist.');
		}
	}

	public static function import($string) {
		return simplexml_load_string($string, 'XML');
	}
}

abstract class Value {
	public static function get(& $variable, $default = '') {
		if (isset ($variable)) {
			return $variable;
		} else {
			return $default;
		}
	}
}

?>
